package boot.spring.controller;

import boot.spring.consts.UserConstants;
import boot.spring.po.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;



@Controller
public class Login {

	@RequestMapping("/")
	public String index(HttpSession httpSession) {
		httpSession.setAttribute("uid", UserConstants.UID);
		return "chatroom";
	}

	@RequestMapping("/loginvalidate")
	public String loginvalidate(@RequestParam("username") String username,@RequestParam("password") String pwd,HttpSession httpSession){
		httpSession.setAttribute("uid", UserConstants.UID);
		return "chatroom";
	}
	
	@RequestMapping("/login")
	public String login(){
		return "login";
	}
	
	@RequestMapping("/logout")
	public String logout(HttpSession httpSession){
		return "login";
	}
	
	@RequestMapping(value="/currentuser",method = RequestMethod.GET)
	@ResponseBody
	public User currentuser(HttpSession httpSession){
		return new User(UserConstants.UID, UserConstants.USER_NAME);
	}
  }
